<template>
  <div slot="header" class="clearfix">
    <el-button style="float: right;margin-bottom: 10px" type="default" size="mini" @click="handleRecord">
      视频记录
    </el-button>
    <el-table class="mt10" v-loading="loading" :data="dataList" border stripe>
      <el-table-column label="文件名称" prop="fileName" align="center"/>
      <el-table-column label="开始时间" align="center" min-width="30">
        <template slot-scope="scope">
          {{ moment(scope.row.createTime).format('yyyy-MM-DD HH:mm:ss') }}
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" min-width="30">
        <template slot-scope="scope">
          {{ moment(scope.row.endTime).format('yyyy-MM-DD HH:mm:ss') }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="20">
        <template #default="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handlePreviews(scope.row)">预览</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <dh-video-record :task-id="taskId" ref="videoRecord" @refresh="getList"/>
  </div>
</template>

<script>
import DhVideoRecord from '@/components/dhVideo/videoRecord'
import { getTaskVideoRecord, removeTaskVideoRecord } from '@/api/oms/task'
import moment from 'moment'
export default {
  name: 'DhVideo',
  components: {DhVideoRecord },
  props: {
    taskId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      dataList: [],
      loading: false
    }
  },
  created() {
    this.getList()
  },
  watch: {
    taskId(){
      this.getList()
    }
  },
  methods: {
    moment,
    handleRecord() {
      this.$refs.videoRecord.dialogVisible = true
    },
    handlePreviews(row) {
      window.open(row.url, "_blank");
    },
    handleDelete(row){
      this.$modal.confirm('是否删除视频记录？').then(() => {
        this.loading = true
        removeTaskVideoRecord(row.id).then(()=>{
          this.getList()
        }).finally(() => {
          this.loading = false
        })
      })
    },
    getList() {
      this.loading = true
      getTaskVideoRecord({taskId: this.taskId}).then(res => {
        this.dataList = res.data
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
